﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Configuration;

namespace TradeMarkSys
{
    public partial class FrmRegTradeMark : Form
    {
        public FrmRegTradeMark()
        {
            InitializeComponent();
        }

        private void FrmRegTradeMark_Load(object sender, EventArgs e)
        {
            try
            {
                dateTimePickerApplyDate.Value = DateTime.Now;
                dateTimePickerAcceptDate.Value = DateTime.Now;
                dateTimePickerApproveDate.Value = DateTime.Now;
                dateTimePickerCertificateDate.Value = DateTime.Now;
                dateTimePickerChargeDate.Value = DateTime.Now;
                dateTimePickerCorrectionsDate.Value = DateTime.Now;
                dateTimePickerDissentDate.Value = DateTime.Now;
                dateTimePickerFirstTrialDate.Value = DateTime.Now;
                dateTimePickerNoticeDate.Value = DateTime.Now;
                dateTimePickerValidityDate.Value = DateTime.Now;
                lblOperater.Text = FrmMain.CurrentUser.UserName;
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = string.Format(@"insert into TradeMark(BaseInfo,RegCode,Tel,CommissionFee,Applicant,KindCode,Address,TradeMarkName,ApplyProject,ApplyDate,ApplyProjectRemark,
Accept,AcceptDate,AcceptRemark,Corrections,CorrectionsDate,CorrectionsRemark,Approve,ApproveDate,ApproveRemark,FirstTrial,FirstTrialDate,FirstTrialRemark,Dissent,DissentDate,DissentRemark,
Notice,NoticeDate,ValidityDate,NoticeRemark,Certificate,CertificateDate,CertificateRemark,Charge,ChargeFee,ChargeDate,ChargeRemark,CreateDateTime,CreatorID) values(
'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',{11},'{12}','{13}',{14},'{15}','{16}',{17},'{18}','{19}',{20},'{21}','{22}',
{23},'{24}','{25}',{26},'{27}','{28}','{29}',{30},'{31}','{32}',{33},{34},'{35}','{36}','{37}',1)", txtBaseInfo.Text,txtRegCode.Text,txtTel.Text,
                                        txtCommissionFee.Text,
                                        txtApplicant.Text,txtKindCode.Text,
                                        txtAddress.Text,txtTradeMarkName.Text,cmbApplyProject.Text,dateTimePickerApplyDate.Value,
                                        txtApplyProjectRemark.Text,checkBoxAccept.Checked,dateTimePickerAcceptDate.Value,txtAcceptRemark.Text,
                                        checkBoxCorrections.Checked,dateTimePickerCorrectionsDate.Value,txtCorrectionsRemark.Text,checkBoxApprove.Checked,
                                        dateTimePickerApproveDate.Value, txtApproveRemark.Text, checkBoxFirstTrial.Checked, dateTimePickerFirstTrialDate.Value,
                                        txtFirstTrialRemark.Text,checkBoxDissent.Checked,dateTimePickerDissentDate.Value,txtDissentRemark.Text,checkBoxNotice.Checked,
                                        dateTimePickerNoticeDate.Value,dateTimePickerValidityDate.Value,txtNoticeRemark.Text,checkBoxCertificate.Checked,
                                        dateTimePickerCertificateDate.Value, txtCertificateRemark.Text, checkBoxCharge.Checked, txtChargeFee.Text.Equals("") ? "0" : txtChargeFee.Text,
                                        dateTimePickerChargeDate.Value,txtChargeRemark.Text,DateTime.Now);
                sql = sql.Replace("\r\n", " ");
                string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+System.Windows.Forms.Application.StartupPath + "\\TradeMarkSys.mdb";
                OleDbConnection conn = new OleDbConnection(connstr);
                OleDbCommand cmd = new OleDbCommand(sql, conn);
                conn.Open();
                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("保存成功");
                }
                else
                {
                    MessageBox.Show("保存失败");
                }
                conn.Close();  
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }

        private void checkBoxAccept_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxAccept.Checked)
                {
                    dateTimePickerAcceptDate.Enabled = true;
                    txtAcceptRemark.Enabled = true;
                }
                else
                {
                    dateTimePickerAcceptDate.Enabled = false;
                    txtAcceptRemark.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }

        private void checkBoxCorrections_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxCorrections.Checked)
                {
                    dateTimePickerCorrectionsDate.Enabled = true;
                    txtCorrectionsRemark.Enabled = true;
                }
                else
                {
                    dateTimePickerCorrectionsDate.Enabled = false;
                    txtCorrectionsRemark.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }

        private void checkBoxApprove_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxApprove.Checked)
                {
                    dateTimePickerApproveDate.Enabled = true;
                    txtApproveRemark.Enabled = true;
                }
                else
                {
                    dateTimePickerApproveDate.Enabled = false;
                    txtApproveRemark.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }

        private void checkBoxFirstTrial_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxFirstTrial.Checked)
                {
                    dateTimePickerFirstTrialDate.Enabled = true;
                    txtFirstTrialRemark.Enabled = true;
                }
                else
                {
                    dateTimePickerFirstTrialDate.Enabled = false;
                    txtFirstTrialRemark.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }

        private void checkBoxDissent_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxDissent.Checked)
                {
                    dateTimePickerDissentDate.Enabled = true;
                    txtDissentRemark.Enabled = true;
                }
                else
                {
                    dateTimePickerDissentDate.Enabled = false;
                    txtDissentRemark.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }

        private void checkBoxNotice_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxNotice.Checked)
                {
                    dateTimePickerNoticeDate.Enabled = true;
                    dateTimePickerValidityDate.Enabled = true;
                    txtNoticeRemark.Enabled = true;
                }
                else
                {
                    dateTimePickerAcceptDate.Enabled = false;
                    dateTimePickerValidityDate.Enabled = false;
                    txtNoticeRemark.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }

        private void checkBoxCertificate_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxCertificate.Checked)
                {
                    dateTimePickerCertificateDate.Enabled = true;
                    txtCertificateRemark.Enabled = true;
                }
                else
                {
                    dateTimePickerCertificateDate.Enabled = false;
                    txtCertificateRemark.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }

        private void checkBoxCharge_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxCharge.Checked)
                {
                    txtChargeFee.Enabled = true;
                    dateTimePickerChargeDate.Enabled = true;
                    txtChargeRemark.Enabled = true;
                }
                else
                {
                    txtChargeFee.Enabled = false;
                    dateTimePickerChargeDate.Enabled = false;
                    txtChargeRemark.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("对不起系统出现错误");
            }
        }
    }
}
